package com.dj.manager.service.impl;

import com.dj.manager.dao.UserMapper;
import com.dj.manager.service.UserService;
import com.dj.pojo.User;
import com.dj.pojo.dto.Pagep;
import com.dj.pojo.dto.UserQuery;
import com.dj.pojo.dto.UserResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class UserServiceImpl implements UserService{
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private UserMapper userMapper;
    @Override
    public UserResult<User> listUser(Pagep pagep, UserQuery userQuery) {
        UserResult<User> result = new  UserResult<User>();
        result.setCode(0);
        result.setMsg("select success");
        try {

           long count =  userMapper.countUser(userQuery);
           result.setCount(count);
           List<User> data = userMapper.listUserBypage(pagep,userQuery);
           result.setData(data);
        }catch (Exception e){
            result.setCode(1);
            result.setMsg("select failed");
            logger.error(e.getMessage(),e);
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public boolean deleteId(Long uid) {
        return userMapper.deleteId(uid);
    }

    @Override
    public User selectProductByPid(Long uid) {
        return userMapper.selectProductByPid(uid);
    }



    @Override
    public int updateUser(User user) {
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public int insertUser(User user) {
        return userMapper.insert(user);
    }


}
